import mysql.connector

# 连接数据库
mydb = mysql.connector.connect(
    host='localhost',
    user='root',
    password=''
)

# 获取游标
cursor = mydb.cursor()

# 查询数据库
cursor.execute('SHOW DATABASES')
for db in cursor:
    print(db)

# 创建数据库
cursor.execute('CREATE DATABASE mydatabase CHARSET="utf8"')

# 关闭数据库连接
cursor.close()
mydb.close()